
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using Swaf.BizObj;

namespace Swaf.Resource.Localization
{
	public enum NumericFormats
	{
		Currency,
		Decimal,
		Scientific,
		FixedPoint,
		General,
		Number,
		Percent,
		RoundTrip,
		Hexadecimal
	}
	public enum DateTimeFormats
	{
		ShortDate,
		LongDate,
		ShortTime,
		LongTime,
		ShortDateTime,
		LongDateTime,
		ShortGeneral,
		LongGeneral,
		MonthDay,
		RC1123,
		Sortable,
		UniversalSortable,
		YearMonth
	}
	public enum NumberTypes
	{
		Decimal,
		Double,
		Float,
		Int,
		Long,
		Short,
		UInt,
		ULong,
		UShort
	}
	/// <summary>
	/// Interface for localization support in CSF
	/// </summary>
	public interface ILocalizationManager
	{
		/// <summary>
		/// The getLocalString method returns the localized string associated with the provided key
		/// or the defaultValue if that key is not found.  This method supports parameter substitution as well
		/// by providing substitutions.  These substitutions can be strings, localization keys or macro names.
		/// To pass in localization keys as substitutions, offset the key with ~ (i.e. ~SomeKey~).  For macros
		/// use the standard macro syntax of $Macro$.
		/// </summary>
		/// <param name="key">The localizatoin id to look up the appropriate string</param>
		/// <param name="defaultValue">The value to return if no local entry is found</param>
		/// <param name="substitutions">values to substitute into the final string using string.Format</param>
		/// <returns></returns>
		string getLocalString(string key, string defaultValue, params object[] substitutions);
		/// <summary>
		/// Clears any locally cached localization strings and reloads (if applicable).
		/// </summary>
		void refreshCache();

		/// <summary>
		/// The format method provides date, time and numeric formatting based on locale settings.
		/// </summary>
		/// <param name="source">Data to be formatted</param>
		/// <returns>formatted string</returns>
		string format(DateTime source, DateTimeFormats format);
		string format(short source, NumericFormats format);
		string format(int source, NumericFormats format);
		string format(long source, NumericFormats format);
		string format(double source, NumericFormats format);
		string format(float source, NumericFormats format);
		string format(decimal source, NumericFormats format);
		string format(uint source, NumericFormats format);
		string format(ulong source, NumericFormats format);
		string format(ushort source, NumericFormats format);

		/// <summary>
		/// Converts a formatted date string back into a date.
		/// </summary>
		/// <param name="source"></param>
		/// <returns></returns>
		DateTime dateFromString(string source);
		/// <summary>
		/// Converts a formatted number back into a number.
		/// </summary>
		/// <param name="source"></param>
		/// <param name="type"></param>
		/// <returns></returns>
		object numberFromString(string source, NumberTypes type);
		/// <summary>
		/// Populates the cache from a list of business objects.
		/// </summary>
		/// <param name="source">IBizObjList to use as source</param>
		/// <param name="cultureField">Name of BizObj field containing the culture string.</param>
		/// <param name="keyField">Name of the field containing the key value</param>
		/// <param name="valueField">Name of the field containing the actual string value.</param>
		void populateFromBizObjList(IBizObjList source, string cultureField, string keyField, string valueField);
		
		/// <summary>
		/// Creates an entry in cache from an IBizObj.
		/// </summary>
		/// <param name="source">IBizObj to use as source</param>
		/// <param name="cultureField">Name of BizObj field containing the culture string.</param>
		/// <param name="keyField">Name of the field containing the key value</param>
		/// <param name="valueField">Name of the field containing the actual string value.</param>
		void populateFromBizObj(IBizObj source, string cultureField, string keyField, string valueField);

	}
}
